package Starter;

import java.io.File;
import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import sr.logger.Logger;
import utils.Options;
import views.MainWindow;



import master.MasterInterface;
import network.MasterCommunicator;

public class EntryClass 
{
	public static void main(String[] args) throws AccessException, RemoteException, NotBoundException
	{
		MasterCommunicator comm = MasterCommunicator.getMasterCommunicator();
		getOptions();
		System.out.println(Options.getInstance().getUser_name());
		try
		{
			comm.connectToMaster();
		} 
		catch(Exception e)
		{
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, "Unable to connect to master server. off.");
			System.exit(1);
		}
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				MainWindow.createAndShowGUI();
				  
			}
		});
		
	}
	
	private static void getOptions()
	{
		try
		{
			File f = new File(".\\opt.xml");
			JAXBContext jaxbContext = JAXBContext.newInstance(Options.class);
			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
			Options.setOptions((Options) jaxbUnmarshaller.unmarshal(f));
		} catch (JAXBException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
